package com.mc.lp.database.dao.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.dao.DataAccessException;

import com.mc.lp.database.dao.IAccessControlDAO;
import com.mc.lp.database.entity.MicroCampusBaseEntity;
import com.mc.lp.database.entity.PermissionEntity;
import com.mc.lp.database.entity.RoleEntity;
import com.mc.lp.database.entity.UserEntity;

public class AccessControlDAOImpl extends
		AbstractGenericHibernateDAO<MicroCampusBaseEntity, Long, IAccessControlDAO> implements
		IAccessControlDAO {

	public List<RoleEntity> getRolesByUserID(Long userID) throws DataAccessException {
		return null;
//		Session session = getCurrentSession();
//
//		UserEntity user = (UserEntity) session.get(UserEntity.class, userID);
//
//		// Criteria crit1 =
//		// session.createCriteria(" from UserRoleEntity where user.id= "+userID);
//
//		Set<RoleEntity> roles = user.getRoles();
//		return roles;
	}

	public Set<PermissionEntity> getPermissionsByRoleID(Long roleID) {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings("unchecked")
	public Set<RoleEntity> getAllRoles() {

		List<RoleEntity> list = (List<RoleEntity>) getCurrentSession()
				.createCriteria(RoleEntity.class).list();

		return new HashSet<RoleEntity>(list);
	}

	public Set<UserEntity> getAllUser() {
		// TODO Auto-generated method stub
		return null;
	}

	public Set<PermissionEntity> getAllPermissions() {
		// TODO Auto-generated method stub
		return null;
	}

	public PermissionEntity getPermissionByID(Long permissionID) {
		// TODO Auto-generated method stub
		return null;
	}

	public RoleEntity getRoleById() {
		// TODO Auto-generated method stub
		return null;
	}

	public RoleEntity getRoleByName(String roleName) {
		// TODO Auto-generated method stub
		return null;
	}

	public PermissionEntity getPermissionByName(String permissionName) {
		// TODO Auto-generated method stub
		return null;
	}

	public void addRoleToUser(String userID, String roleID) throws DataAccessException {

//		UserEntity user = (UserEntity) findById(Long.valueOf(userID), UserEntity.class);
//		Set<RoleEntity> roles = user.getRoles();
//		RoleEntity role = (RoleEntity) findById(Long.valueOf(roleID), RoleEntity.class);
//		roles.add(role);
//		user.setRoles(roles);
//		save(user);

	}

}
